package com.project.filter;

import javax.servlet.*;
import java.io.IOException;

public class CharFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("utf-8");
        servletResponse.setContentType("text/html;charset=utf-8");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    //    /**
//     * 3.注册过滤器
//     */
//    private void registerFilter(Filter filter, String urlPattern, Context context){
//        FilterDef fd1=new FilterDef();
//        fd1.setFilter(filter);//设置过滤器
//        fd1.setFilterName(filter.getClass().getSimpleName());//设置过滤器名称
//
//        FilterMap fm1=new FilterMap();
//        fm1.setFilterName(filter.getClass().getSimpleName());
//        fm1.addURLPattern(urlPattern);//设置过滤器范围
//
//        context.addFilterDef(fd1);
//        context.addFilterMap(fm1);
//    }

//       this.registerFilter(new AddSpeakFilter(),"/speak/add",context);


//     <!--    文件上传依赖-->
//        <dependency>
//            <groupId>commons-fileupload</groupId>
//            <artifactId>commons-fileupload</artifactId>
//            <version>1.4</version>
//        </dependency>
//        <dependency>
//            <groupId>commons-io</groupId>
//            <artifactId>commons-io</artifactId>
//            <version>2.3</version>
//        </dependency>
}
